package com.wx.business.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class TradeNoGenerater {

	
	public static final String COUPON_NUMBER = "QQ"; //优惠券
	
	public static final String REBATE_NUMBER = "8001"; //返利
	
	public static final String TRANSFER_NUMBER = "ZZ"; //用户转账
	
	public static final String BONUSES_NUMBER = "JL"; //用户转账
	
	public static final String DRAW_NUMBER = "TX"; // 流水号 提现
	
	public static final String PAY_OUT_NUMBER = "PO"; // 流水号格式 支出
	
	public static final String INCOME_NUMBER = "IC"; // 流水号格式 入账
	
    public static final String PAY_OUT_REFUND = "POR"; // 退款流水号格式 支出
	
	public static final String INCOME_REFUND = "ICR"; //退款 流水号格式 入账
	
	public static final String TOP_UP_NUMBER = "CZ"; // 流水号格式 充值
	
	public static final String MS_NUMBER = "MS"; // 购买秘书流水号格式
	
	public static final String AS_NUMBER = "AS"; // 售后流水号格式
	
	public static final String SS_NUMBER = "SS"; // 店铺等级购买充值
	
	private static TradeNoGenerater TradeNoGenerater = null;

	private TradeNoGenerater() {
	}

	/**
	 * 取得TradeNoGenerater的单例实现
	 * 
	 * @return
	 */
	public static TradeNoGenerater getInstance() {
		if (TradeNoGenerater == null) {
			synchronized (TradeNoGenerater.class) {
				if (TradeNoGenerater == null) {
					TradeNoGenerater = new TradeNoGenerater();
				}
			}
		}
		return TradeNoGenerater;
	}

	
	/**
	 * 店铺等级购买
	 */
	public synchronized String generaterTransferShopNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return SS_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	/**
	 * 返利的流水号
	 */
	public synchronized String generaterRebateTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return REBATE_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	/**
	 * 生成用户转账订单号
	 */
	public synchronized String generaterTransferOrderNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return TRANSFER_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	
	/**
	 * 生成用户推荐奖励转账订单号
	 */
	public synchronized String generaterBonusesTransferOrderNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return BONUSES_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	
	
	/**
	 * 生成用购买优惠券的主流水号
	 */
	public synchronized String generaterCouponTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return COUPON_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	
	
	/**
	 * 生成支出流水号
	 */
	public synchronized String generaterPayTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return PAY_OUT_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	
	/**
	 * 生成入账流水号
	 */
	public synchronized String generaterIncomeTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return INCOME_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	/**
	 * 退款生成支出流水号
	 */
	public synchronized String generaterRefundPayTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return PAY_OUT_REFUND+date+getTwo()+seconds+getTwo();
	}
	
	
	/**
	 * 退款生成入账流水号
	 */
	public synchronized String generaterRefundIncomeTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return INCOME_REFUND+date+getTwo()+seconds+getTwo();
	}
	
	
	/**
	 * 生成充值流水号
	 */
	public synchronized String generaterTopUpTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return TOP_UP_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	/**
	 * 生成购买秘书流水号
	 */
	public synchronized String generaterMSTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return MS_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	/**
	 * 生成入账流水号
	 */
	public synchronized String generaterMainTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return date+getTwo()+seconds+getTwo();
	}
	
	/**
	 * 生成售后主流水号
	 */
	public synchronized String generaterAfterSaleMainTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return AS_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	
	/**
	 * 提现生成支出流水号
	 */
	public synchronized String generaterDrawFeeTradeNo() {
		   String date = new SimpleDateFormat("yyMMdd").format(new Date());  
	       String seconds = new SimpleDateFormat("HHmmss").format(new Date());  
		return DRAW_NUMBER+date+getTwo()+seconds+getTwo();
	}
	
	/** 
     * 产生随机的2位数 
     * @return 
     */  
    public static String getTwo(){  
        Random rad=new Random();  
  
        String result  = rad.nextInt(100) +"";  
  
        if(result.length()==1){  
            result = "0" + result;  
        }  
        return result;  
    }  
}